package com.springboot.killingsystem.service;

import com.springboot.killingsystem.dao.GoodsDao;
import com.springboot.killingsystem.domain.SecondKillingGoods;
import com.springboot.killingsystem.vo.GoodsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsService {
    @Autowired
    GoodsDao goodsDao;

    public List<GoodsVo> getGoodsVoList() {
        return goodsDao.getGoodsVoList();
    }


    public GoodsVo getGoodsVoByGoodsId(long goodsId) {
        return goodsDao.getGoodsVoByGoodsId(goodsId);
    }

    public boolean reduceStock(GoodsVo goods) {
        SecondKillingGoods g = new SecondKillingGoods();
        g.setGoodsId(goods.getId());
        g.setStockCount(goods.getStockCount());
        int res = goodsDao.reduceStock(g);
        return res > 0;
    }
}
